/**
 * creation: 7-mrt-2008
 */
package org.jfonia.connect;

/**
 * Convenience abstract class for implementations of Callable
 * which mutate (set) a MutableValue.  
 * 
 * @author wijnand.schepens@gmail.com
 *
 */
public abstract class Mutator<T> implements Callable
{
	protected MutableValue<T> source;

	public Mutator(MutableValue<T> source)
	{
		this.source = source;
	}

	/**
	 * Source value is set to new value obtained by calculate(old source value).
	 * @return always returns true
	 */
	public boolean call(Object param)
	{
		source.set(calculate(source.get()));
		return true;
	}
	
	/**
	 * abstract method used to calculate the new source value from the old source value.
	 * @param value
	 * @return
	 */
	protected abstract T calculate(T value);
}
